package com.chaoyong.higo.fragment;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.entity.StringEntity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.chaoyong.higo.R;
import com.chaoyong.higo.activity.LimitShopActivity;
import com.chaoyong.higo.activity.LoginActivity;
import com.chaoyong.higo.activity.ProductDeTimeActivity;
import com.chaoyong.higo.activity.PurchaseRecordActivity;
import com.chaoyong.higo.activity.SearchActivity;
import com.chaoyong.higo.activity.SharActivity;
import com.chaoyong.higo.activity.SharDetailActivity;
import com.chaoyong.higo.adapter.NewsAdapter;
import com.chaoyong.higo.base.BaseFragment;
import com.chaoyong.higo.bean.ListEntity2;
import com.chaoyong.higo.bean.NewsAnnoBean;
import com.chaoyong.higo.bean.SharBean;
import com.chaoyong.higo.bean.ShowOrderEntity;
import com.chaoyong.higo.bean.DaoJSBean.DataEntity.ListEntity;
import com.chaoyong.higo.utils.EmptyUtil;
import com.chaoyong.higo.utils.JLog;
import com.chaoyong.higo.utils.Mlog;
import com.chaoyong.higo.utils.PrefUtils;
import com.chaoyong.higo.utils.TransferTool;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.view.AutoScrollViewPager;
import com.chaoyong.higo.view.CustomProgressDialog;
import com.chaoyong.higo.view.TitleView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * ��ҳ
 * 
 * @author 丁晶
 * 
 */
public class FragHomePage extends BaseFragment implements OnClickListener, OnRefreshListener, OnItemClickListener {

	private TitleView fragmain_title;
	private RecyclerView recommend_recycler;
	//private PullToRefreshScrollView fragmain_refresh;
	private ImageView fraghome_new, fraghome_share, fraghome_list;
	private ImageButton fragmain_new_imgbt, freghome_recommend_imabt,
			fragmain_shar_imgbt;
	private ImageView shar1_img, shar3_img, shar2_img;
	private TextView shar1_tx, shar2_tx, shar3_tx;
	private AutoScrollViewPager main_vPager;
	private List<String> list;
	private LayoutInflater inflater;
	private List<View> views;
	private View item;
	private ImageView item_view;
	private List<ListEntity2> listr;
	private List<ListEntity> entities;
	private MyAdapters adapter;
	/**最新揭晓*/
	private NewsAdapter mAdapter;
	private ImageView xian1_img, xian2_img, xian3_img, xian4_img, xian5_img;
	
	private GridView news_lay;
	
	private ViewGroup group;
	private ImageView[] imageViews;
	
	private CustomProgressDialog dialog;


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		mView = inflater.inflate(R.layout.frag_home_page, container, false);
		return mView;
	}

	@Override
	public void findView() {
		fragmain_title = (TitleView) mView.findViewById(R.id.fragmain_title);
		// 自动轮播
		main_vPager = (AutoScrollViewPager) mView.findViewById(R.id.main_vPagers);
		main_vPager.setInterval(4000);
		main_vPager.startAutoScroll();
		
		//fragmain_refresh = (PullToRefreshScrollView) mView.findViewById(R.id.fragmain_refresh);
		//fragmain_refresh.scrollTo(0, 0);
		
		main_vPager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				for (int i = 0; i < imageViews.length; i++) {
					if(arg0 == i){
						imageViews[arg0].setBackgroundResource(R.drawable.dot1);
					}
					if (arg0 != i) {
						imageViews[i].setBackgroundResource(R.drawable.dot0);
					}
				}
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		// 人气推荐
		recommend_recycler = (RecyclerView) mView.findViewById(R.id.freghome_recommend_recycler);
		fraghome_new = (ImageView) mView.findViewById(R.id.fraghome_new_imgbt);
		fraghome_list = (ImageView) mView.findViewById(R.id.fraghome_list_imgbt);
		fraghome_share = (ImageView) mView.findViewById(R.id.fraghome_share_imgbt);
		fragmain_new_imgbt = (ImageButton) mView.findViewById(R.id.fragmain_new_imgbt);
		freghome_recommend_imabt = (ImageButton) mView.findViewById(R.id.freghome_recommend_imabt);
		// 晒单
		fragmain_shar_imgbt = (ImageButton) mView.findViewById(R.id.fragmain_shar_imgbt);
		shar1_img = V.f(mView, R.id.fraghome_shar1_img);
		shar2_img = V.f(mView, R.id.fraghome_shar2_img);
		shar3_img = V.f(mView, R.id.fraghome_shar3_img);

		shar1_tx = V.f(mView, R.id.fraghome_shar1_tx);
		shar2_tx = V.f(mView, R.id.fraghome_shar2_tx);
		shar3_tx = V.f(mView, R.id.fraghome_shar3_tx);

		xian1_img = V.f(mView, R.id.fraghome_xian1_img);
		xian2_img = V.f(mView, R.id.fraghome_xian2_img);
		xian3_img = V.f(mView, R.id.fraghome_xian3_img);
		xian4_img = V.f(mView, R.id.fraghome_xian4_img);
		xian5_img = V.f(mView, R.id.fraghome_xian5_img);
		// 最新揭晓
		news_lay = V.f(mView, R.id.news_lay);

		fraghome_new.setOnClickListener(this);
		fraghome_list.setOnClickListener(this);
		fraghome_share.setOnClickListener(this);
		fragmain_new_imgbt.setOnClickListener(this);
		freghome_recommend_imabt.setOnClickListener(this);
		fragmain_shar_imgbt.setOnClickListener(this);

		shar1_img.setOnClickListener(this);
		shar2_img.setOnClickListener(this);
		shar3_img.setOnClickListener(this);
		xian1_img.setOnClickListener(this);
		xian2_img.setOnClickListener(this);
		xian3_img.setOnClickListener(this);
		xian4_img.setOnClickListener(this);
		xian5_img.setOnClickListener(this);

		group = V.f(mView, R.id.viewGroup);
		group.setPadding(0, 0, 5, -5);

		dialog = new CustomProgressDialog(mContext, "正在加载中...", R.anim.frame);
		//dialog.show();
	}

	@Override
	public void init() {
		fragmain_title.setFocusable(true);
		fragmain_title.setFocusableInTouchMode(true);
		fragmain_title.requestFocus();
		fragmain_title.setTitleText("嗨购夺宝", mContext.getResources().getColor(R.color.white));
		fragmain_title.setTitleBack(mContext.getResources().getColor(R.color.red_title));
		fragmain_title.setRightImage(R.drawable.title_search);
		fragmain_title.setonRightClinck(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext, SearchActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
		});

		// fragmain_refresh.setOnRefreshListener(this);
		inflater = LayoutInflater.from(mContext);
		list = new ArrayList<String>();
		views = new ArrayList<View>();
		mainImage();

		listr = new ArrayList<ListEntity2>();
		entities = new ArrayList<ListEntity>();
		// 最新揭晓
		mAdapter = new NewsAdapter(mContext);
		news_lay.setAdapter(mAdapter);
		news_lay.setOnItemClickListener(this);
		
		xian1_img.setImageResource(R.drawable.xian1);
		xian2_img.setImageResource(R.drawable.xian2);
		xian3_img.setImageResource(R.drawable.xian3);
		xian4_img.setImageResource(R.drawable.xian4);
		xian5_img.setImageResource(R.drawable.xian5);
		// 人气推荐
		recommend_recycler.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));
		recommend();
		// 晒单、、
		shar();

	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		news();
	}
/**最新揭晓*/
	private void news() {
		HttpUtils utils = new HttpUtils();
		RequestParams param = new RequestParams();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.putOpt("model", "GoodsStatus");
			jsonObject.putOpt("app", "1");
			jsonObject.putOpt("function", "getGoodsStatus");
			jsonObject.putOpt("code", "0,4");
			param.setBodyEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		utils.send(HttpMethod.POST, Values.MAIN_RECOMMEND, param, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				try {
					JSONObject jsonObject = new JSONObject(arg0.result);
					if (jsonObject.getString("status").equals("1")) {
						Gson gson = new Gson();
						NewsAnnoBean bean = gson.fromJson(arg0.result, NewsAnnoBean.class);
						if(!EmptyUtil.isEmpty(bean.getData().getList())){
							List<NewsAnnoBean.DataEntity.ListEntity> entity = bean.getData().getList();
							mAdapter.setList(entity);
						}
					}
					
				} catch (JSONException e) {
					e.printStackTrace();
				}
				
				dialog.dismiss();
			}
		});
			
	}

	@Override
	public void onRefresh(PullToRefreshBase refreshView) {
	}

	private ShowOrderEntity soe1;
	private ShowOrderEntity soe2;
	private ShowOrderEntity soe3;

	// 晒单
	private void shar() {
		HttpUtils utils = new HttpUtils();
		RequestParams param = new RequestParams();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.putOpt("model", "Share");
			jsonObject.putOpt("app", "1");
			jsonObject.putOpt("function", "getAllShares");
			jsonObject.putOpt("code", "3,,recommend_sort DESC");
			param.setBodyEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		//Mlog.d("人气推荐url=", Values.MAIN_RECOMMEND);
		utils.send(HttpMethod.POST, Values.MAIN_RECOMMEND, param, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				showToast("网络请求失败");
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				Mlog.d("rerult=", result);
				if (result != null) {
					try {
						JSONObject object = new JSONObject(result);
						if (object.getString("status").equals("1")) {
							// JSONObject objec=new
							// JSONObject(object.getString("data"));
							if (object.getString("data") != null) {
								JSONObject jso = object.getJSONObject("data");
								String s = jso.getString("list");
								//String ss = jso.getString("list");
								//if(s != null && "null".equals(ss)){
									if(!TextUtils.isEmpty(s)){
									
								Gson gson = new GsonBuilder().create();
								SharBean image = gson.fromJson(result, new TypeToken<SharBean>() {
								}.getType());
								
								JSONArray ja = jso.getJSONArray("list");
								if(ja.length() == 1){
									soe1 = image.getData().getList().get(0);
									JSONArray arra1 = new JSONArray(image.getData().getList().get(0).getFace_img());
									BitmapUtils tUtils = new BitmapUtils(mContext);
									tUtils.display(shar1_img, arra1.getString(0));
									shar1_tx.setText(image.getData().getList().get(0).getShare_title());
								}else if(ja.length() == 2){
									soe1 = image.getData().getList().get(0);
									soe2 = image.getData().getList().get(1);
									JSONArray arra1 = new JSONArray(image.getData().getList().get(0).getFace_img());
									JSONArray arra2 = new JSONArray(image.getData().getList().get(1).getFace_img());
									BitmapUtils tUtils = new BitmapUtils(mContext);
									tUtils.display(shar1_img, arra1.getString(0));
									BitmapUtils tUtil = new BitmapUtils(mContext);
									tUtil.display(shar2_img, arra2.getString(0));
									shar1_tx.setText(image.getData().getList().get(0).getShare_title());
									shar2_tx.setText(image.getData().getList().get(1).getShare_title());
								}else if(ja.length() == 3){
									soe1 = image.getData().getList().get(0);
									soe2 = image.getData().getList().get(1);
									soe3 = image.getData().getList().get(2);
									JSONArray arra1 = new JSONArray(image.getData().getList().get(0).getFace_img());
									// JSONArray arra1=new
									// JSONArray(image.getList().get(0).getFace_img());
									JSONArray arra2 = new JSONArray(image.getData().getList().get(1).getFace_img());
									JSONArray arra3 = new JSONArray(image.getData().getList().get(2).getFace_img());
									BitmapUtils tUtils = new BitmapUtils(mContext);
									tUtils.display(shar1_img, arra1.getString(0));
									BitmapUtils tUtil = new BitmapUtils(mContext);
									tUtil.display(shar2_img, arra2.getString(0));
									BitmapUtils tUtil1 = new BitmapUtils(mContext);
									tUtil1.display(shar3_img, arra3.getString(0));
									
									shar1_tx.setText(image.getData().getList().get(0).getShare_title());
									shar2_tx.setText(image.getData().getList().get(1).getShare_title());
									shar3_tx.setText(image.getData().getList().get(2).getShare_title());
								}
								
								}
							}
						}

					} catch (JSONException e) {
						e.printStackTrace();
					}

				}
			}
		});

	}

	private void recommend() {
		HttpUtils utils = new HttpUtils();
		RequestParams param = new RequestParams();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.putOpt("model", "GoodsStatus");
			jsonObject.putOpt("app", "1");
			jsonObject.putOpt("function", "getGoodsStatus");
			jsonObject.putOpt("code", "1,10");
			param.setBodyEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		utils.send(HttpMethod.POST, Values.MAIN_RECOMMEND, param, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				showToast("网络请求失败");
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				Mlog.d("rerult=", result);
				if (result != null) {
					try {
						JSONObject object = new JSONObject(result);
						if (object.getString("status").equals("1")) {
							if (object.getString("data") != null) {

								JSONObject object2 = new JSONObject(object.getString("data"));
								Gson gson = new GsonBuilder().create();
								listr = gson.fromJson(object2.getString("list"), new TypeToken<List<ListEntity2>>() {
								}.getType());
							}
							adapter = new MyAdapters();
							adapter.notifyDataSetChanged();
							recommend_recycler.setAdapter(adapter);
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
			}
		});
	}

	private void mainImage() {
		HttpUtils utils = new HttpUtils();
		RequestParams param = new RequestParams();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("common", "get_carousel");
			jsonObject.putOpt("code", "21");
			param.setBodyEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		utils.send(HttpMethod.POST, Values.MAIN_IMAGE, param, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Mlog.d("result=" + "网络失败");
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				Mlog.d("result=" + result);
				// Gson gson=new GsonBuilder().create();
				// MainImageBean imageBean=gson.fromJson(result,new
				// TypeToken<MainImageBean>(){}.getType());
				JSONObject object;
				try {
					object = new JSONObject(result);
					if (object.getString("status").equals("1")) {
						JSONArray array = new JSONArray(object.getString("data"));
						for (int i = 0; i < array.length(); i++) {
							list.add(array.getString(i));
						}
						for (int i1 = 0; i1 < list.size(); i1++) {
							item = inflater.inflate(R.layout.item_image, null);
							views.add(item);
						}
						
						imageViews = new ImageView[views.size()];
						for (int i = 0; i < views.size(); i++) {
							ImageView img = new ImageView(mContext);
							
							LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(10, 10);
							params.setMargins(4, 10, 4, 10);
							img.setLayoutParams(params);
							imageViews[i] = img;
							if(i == 0){
								imageViews[i].setBackgroundResource(R.drawable.dot1);
							}else{
								imageViews[i].setBackgroundResource(R.drawable.dot0);
							}
							group.addView(imageViews[i]);
						}
						
						main_vPager.setAdapter(new imageAdapter(views));
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
				//dialog.dismiss();
			}
		});

		// main_vPager.setOnPageChangeListener(new ImageListener());
	}

	class imageAdapter extends PagerAdapter {
		private List<View> lists;

		public imageAdapter(List<View> lists) {
			super();
			this.lists = lists;
		}

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			View view = lists.get(position);
			item_view = (ImageView) view.findViewById(R.id.item_view);
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + list.get(position).toString(), item_view);
			container.addView(lists.get(position));
			
			return lists.get(position);
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			container.removeView(lists.get(position));
		}
		
	}

	// 人气推荐adapter
	class MyAdapters extends RecyclerView.Adapter<MyAdapters.MyViewHolder> {

		class MyViewHolder extends ViewHolder {
			LinearLayout layout;
			TextView textView, count, total, left,itemhome_title_name;
			ImageView image;
			ProgressBar bar;

			public MyViewHolder(View arg0) {
				super(arg0);
				layout = (LinearLayout) arg0.findViewById(R.id.itemhome_recom_lay);
				textView = (TextView) arg0.findViewById(R.id.itemhome_price_tx);
				itemhome_title_name = (TextView) arg0.findViewById(R.id.itemhome_title_name);
				image = (ImageView) arg0.findViewById(R.id.itemhome_image_img);
				bar = (ProgressBar) arg0.findViewById(R.id.itemhome_count_Pro);

				count = (TextView) arg0.findViewById(R.id.itemhome_count_tx);
				total = (TextView) arg0.findViewById(R.id.itemhome_total_tx);
				left = (TextView) arg0.findViewById(R.id.itemhome_left_tx);
			}

		}

		@Override
		public int getItemCount() {
			return listr.size();
		}

		@Override
		public void onBindViewHolder(MyViewHolder holder, final int arg1) {
			int left = TransferTool.Strtoint(listr.get(arg1).getGoods_price(), ".") - listr.get(arg1).getSurplus();
			String total = TransferTool.getString(listr.get(arg1).getGoods_price(), ".");
			holder.textView.setText(listr.get(arg1).getGoods_price());
			holder.count.setText(listr.get(arg1).getSurplus() + "");
			holder.total.setText(total);
			holder.left.setText(TransferTool.toString(left));
			holder.itemhome_title_name.setText("(第" + listr.get(arg1).getExpect() + mContext.getResources().getString(R.string.expect) + ")" + listr.get(arg1).getGoods_name());
			//Double double1 = (double) (listr.get(arg1).getSurplus()) / (TransferTool.toInt(total) / 100);
			Double d = (double) ((listr.get(arg1).getSurplus() / Double.parseDouble(listr.get(arg1).getGoods_price())) *  100.00);

			//int pro = d.intValue();
			if(d < 1 && d > 0){
				holder.bar.setProgress(1);
			}else{
				holder.bar.setProgress(d.intValue());
			}
			BitmapUtils tUtils = new BitmapUtils(mContext);
			tUtils.display(holder.image, listr.get(arg1).getImg_n());
			holder.layout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO 跳转到商品详情
					Intent i = new Intent(mContext, ProductDeTimeActivity.class);
					i.putExtra("listEntity2", listr.get(arg1));
					startActivity(i);
				}
			});
		}

		@Override
		public MyViewHolder onCreateViewHolder(ViewGroup arg0, int arg1) {
			MyViewHolder holder = new MyViewHolder(
					LayoutInflater.from(mContext).inflate(R.layout.item_home_recom, arg0, false));
			return holder;
		}

	}

	// 接口监听跳转
	public interface SetClickListener {
		void onNewClick();

		void onShopsClick();

		void onNIClick();
		
		void onUser();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.fraghome_list_imgbt:
			if(PrefUtils.getBoolean(mContext, "isLogin", false)){
				startActivity(new Intent(mContext, PurchaseRecordActivity.class));
			}else{
				Intent intent = new Intent(mContext, LoginActivity.class);
				startActivity(intent);
				getActivity().overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_top);
			}
			break;
		case R.id.fraghome_new_imgbt:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		case R.id.fraghome_share_imgbt:
			startActivity(new Intent(mContext, SharActivity.class));
			break;
		// 点击跳转到最新揭晓
		case R.id.fragmain_new_imgbt:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onNewClick();
			}
			break;
		// 点击跳转到最新揭晓
		case R.id.freghome_recommend_imabt:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		case R.id.fragmain_shar_imgbt:
			startActivity(new Intent(mContext, SharActivity.class));
			break;
		case R.id.fraghome_shar1_img:
			Intent i1 = new Intent(mContext, SharDetailActivity.class);
			i1.putExtra("sharEntity", soe1);
			startActivity(i1);
			break;
		case R.id.fraghome_shar2_img:
			Intent i2 = new Intent(mContext, SharDetailActivity.class);
			i2.putExtra("sharEntity", soe2);
			startActivity(i2);
			break;
		case R.id.fraghome_shar3_img:
			Intent i3 = new Intent(mContext, SharDetailActivity.class);
			i3.putExtra("sharEntity", soe3);
			startActivity(i3);
			break;
		case R.id.fraghome_xian1_img:
			startActivity(new Intent(mContext, LimitShopActivity.class));
			break;
		case R.id.fraghome_xian2_img:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		case R.id.fraghome_xian3_img:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		case R.id.fraghome_xian4_img:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		case R.id.fraghome_xian5_img:
			if (getActivity() instanceof SetClickListener) {
				((SetClickListener) getActivity()).onShopsClick();
			}
			break;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		if (getActivity() instanceof SetClickListener) {
			((SetClickListener) getActivity()).onNewClick();
		}
	}

}
